﻿using ERP.Framework.Components.Utilities.CloningHelper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections;
using ERP.Framework.Components.Testing.SerializationHelper.Test;
namespace ERP.Framework.Components.Testing
{
    
    
    /// <summary>
    ///This is a test class for CloningHelperTest and is intended
    ///to contain all CloningHelperTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CloningHelperTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Clone
        ///</summary>
        [TestMethod()]
        public void CloneTest()
        {
            SerializingTestObject objToClone = new SerializingTestObject(); 
            objToClone.Name = "Clone Test Object";
            Hashtable ht = new Hashtable();
            ht.Add(1, "List with Hash table");
            objToClone.TestList.Add(ht);
            objToClone.TestList.Add("Default list item");

            object actual = CloningHelper.Clone(objToClone);
            
            //Test cases
            //Check null
            Assert.IsNotNull(actual);
            //Check objects type
            Assert.AreEqual(actual.GetType(), typeof(SerializingTestObject));
            Assert.AreEqual(objToClone.GetType(), actual.GetType());
            //Check properties
            Assert.AreEqual(objToClone.ID, ((SerializingTestObject)actual).ID);
            Assert.AreEqual(objToClone.Name, ((SerializingTestObject)actual).Name);
            Assert.AreEqual(objToClone.RandomNumber, ((SerializingTestObject)actual).RandomNumber);
            Assert.AreEqual(objToClone.TestList.Count, ((SerializingTestObject)actual).TestList.Count);
            for (int i = 0; i < objToClone.TestList.Count; i++ )
            {
                Assert.AreEqual(objToClone.TestList[i].GetType(), ((SerializingTestObject)actual).TestList[i].GetType());
                //Assert.AreEqual(objToClone.TestList[i], ((SerializingTestObject)actual).TestList[i]);
            }            
        }
    }
}
